/*
 * @Description: 
 * @version: 
 * @Author: Eve
 * @Date: 2019-10-08 22:47:47
 * @LastEditors: Eve
 * @LastEditTime: 2019-10-09 19:33:32
 */
var a = 10
function foo() {
	console.log(a)
	// var a = 8;
}
foo()

// 输出undefined
/* 
实际等于
var a;
a = 10;
foo()=>内部作用域又变成了这样
var a;
console.log(a);  此时a是undefined
a = 8;
*/

// var a2 = 10
// function foo2() {
// 	console.log(a2)
// 	let a2 = 8
// }
// foo2()

/* 
会报错 a2 is not defined

*/

var array = []
for (var i = 0; i < 3; i++) {
	array.push(() => i)
}
var newArray = array.map(el => el())
console.log(newArray) // ??

/* 
3,3,3
因为当Push执行时读取的仍是i 而此时循环已经完成 i=3 所以push的都是3
*/

console.log('JS有多少种数据类型？')
console.log(typeof function name(params) {})
console.log(typeof {})
console.log(typeof [])
console.log(typeof Symbol())
console.log(typeof new Set())
console.log(typeof new WeakSet())
console.log(typeof new Map())
console.log(typeof new WeakMap())
console.log(typeof '')
console.log(typeof 1)
console.log(typeof true)
console.log(typeof null)
console.log(typeof undefiend)

let setArr = [1, 3, 4, 2, 4, 5, 6, 22, 11, 0.9, -1, 1, 11, 0.9, -1]

function sele(arr) {
	/* 
  这里的逻辑是 
  双层循环 只要往后没有找到重复的就添加
  所以第一个数才会是3
  所以结果应该是 3,2,4,5,6,22,1,11,0.9,-1
  */
	var temp = []
	for (var i = 0; i < arr.length; i++) {
		for (var j = i + 1; j < arr.length; j++) {
			if (arr[i] === arr[j]) {
				console.log(arr[i], arr[j], i, j)
				j = ++i
			}
		}
		console.count('运行了多少次')
		temp.push(arr[i])
	}
	return temp
}

console.log(sele(setArr))
let resArr = []
setArr.forEach(item => resArr.includes(item) || resArr.push(item))
console.log('filter', resArr)
